home *** CD-ROM | disk | FTP | other *** search
/ NOVA - For the NeXT Workstation / NOVA - For the NeXT Workstation.iso / Documents / NeXTAnswers / objc.776 < prev    next >
Text File  |  1992-02-06  |  1KB  |  49 lines

  1. {\rtf0\ansi{\fonttbl\f1\fnil Times-Roman;\f3\fmodern Ohlfs;\f0\fswiss Helvetica;}
  2. \paperw13040
  3. \paperh10800
  4. \margl120
  5. \margr120
  6. {\colortbl\red0\green0\blue0;}
  7. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\f1\b0\i0\ul0\fs28 C++ new error handler\
  8. \
  9. Q:  In C++, how can I override the error handler for the 
  10. \b new
  11. \b0  operator?  I can do this with other compilers, but it doesn't work with the NeXT C++ compiler.\
  12. \
  13. A: On the NeXT, you can override the error for the 
  14. \b new
  15. \b0  operator in the following way.  Define a routine, say, 
  16. \b newErrorHandler
  17. \b0 :\
  18.  
  19. \f3\fs22\fc0     \
  20.     static void newErrorHandler()\
  21.     \{\
  22.         fprintf(stderr, "new: Failed to 
  23. \pard\tx520\tx1060\tx1600\tx2120\tx2660\tx3200\tx3720\tx4260\tx4800\tx5320\fc0 acquire
  24. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fc0  sufficient memory.");\
  25.         fflush(stderr);\
  26.     \}\
  27. \
  28.  
  29. \f1\fs28 Then, somewhere in your initialization routines call 
  30. \b set_new_handler
  31. \b0 :\
  32.  
  33. \f3\fs22 \
  34.     set_new_handler(newErrorHandler);\
  35.  
  36. \pard\tx620\tx1240\tx1860\tx2480\tx3100\tx3720\tx4340\tx4980\tx5600\tx6220\fc0 \
  37.  
  38. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\f1\b\fs28\fc0 newErrorHandler
  39. \b0  will be called whenever an error is encountered during the 
  40. \b new
  41. \b0  operation.\
  42. \
  43. QA776\
  44. \
  45. Valid for 1.0\
  46. Valid for 2.0\
  47. \
  48.  
  49.